package gtug.duesseldorf.client.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class ClientCommand implements Serializable {

	private static final long serialVersionUID = 1L;

	private ClientWaveId m_waveId;
	private List<String> m_messageData;
	private boolean m_messageDataDelta;
	private ClientWaveList m_waveList;
	private ArrayList<ClientParticipant> m_participantList;
	private boolean m_doOpenWave;

	/**
	 * used for serialization
	 */
	@SuppressWarnings("unused")
	private ClientCommand() {

	}

	public ClientCommand(ClientWaveId waveId) {
		m_waveId = waveId;
	}

	@Override
	public String toString() {
		StringBuffer buf = new StringBuffer();
		buf.append("ClientCommand: ").append("\n");
		buf.append("WaveId: ").append(m_waveId).append("\n");

		buf.append("Data: ");
		if (m_messageData == null) {
			buf.append("null");
		} else {
			buf.append("Delta=").append(m_messageDataDelta ? true : false);

			for (String s : m_messageData) {
				buf.append(s).append(", ");
			}
		}

		buf.append("\n");
		buf.append("WaveList: ").append(m_waveList).append("\n");
		buf.append("Participants: ").append(m_participantList).append("\n");

		return buf.toString();
	}

	public ClientWaveId getWaveId() {
		return m_waveId;
	}

	public void setMessageData(List<String> messageData, boolean messageDataDelta) {
		m_messageData = messageData;
		m_messageDataDelta = messageDataDelta;
	}

	public List<String> getMessageData() {
		return m_messageData;
	}

	public boolean isMessageDataDelta() {
		return m_messageDataDelta;
	}

	public void setWaveList(ClientWaveList waveList) {
		m_waveList = waveList;
	}

	public ClientWaveList getWaveList() {
		return m_waveList;
	}

	public void setDoOpenWave(boolean doOpenWave) {
		m_doOpenWave = doOpenWave;
	}

	public boolean isDoOpenWave() {
		return m_doOpenWave;
	}

	public ArrayList<ClientParticipant> getParticipantList() {
		return m_participantList;
	}

	public void addParticipant(String participantId) {
		if (m_participantList == null) {
			m_participantList = new ArrayList<ClientParticipant>();
		}

		m_participantList.add(new ClientParticipant(participantId, m_waveId, true));
	}

	public void removeParticipant(String participantId) {
		if (m_participantList == null) {
			m_participantList = new ArrayList<ClientParticipant>();
		}

		m_participantList.add(new ClientParticipant(participantId, m_waveId, false));
	}

}
